package com.teamwings.common.query;

import lombok.Data;

import java.io.Serializable;

@Data
public class QueryCondition implements Serializable {

	private static final long serialVersionUID = 4740166316629191651L;

	// 字段名称
	private String field;
	private String type;
	// 规则
	private String rule;
	// 数值
	private String val;
	// and or
	private String matchType;
	// 是否使用系统变量
	private Boolean isSystemVariable;


	@Override
	public String toString(){
		StringBuffer sb =new StringBuffer();
		if(field == null || "".equals(field)){
			return "";
		}
		sb.append(this.field).append(" ")
				.append(this.rule)
				.append(" ").append(this.type)
				.append(" ");

		if (this.isSystemVariable != null && this.isSystemVariable) {
			sb.append(getSystemVariable(this.val));
			this.setVal(getSystemVariable(this.val));
		} else {
			sb.append(this.val);
		}

		return sb.toString();
	}

	private String getSystemVariable(String val) {
		String tempVal = "";
//        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
		switch (val) {
			case "currUserId" :
//                tempVal = sysUser.getId();
				break;
			case "currUserName" :
//                tempVal = sysUser.getUsername();
				tempVal = "admin";
				break;
			case "currUserDeptId" :
				break;
			case "currUserDeptName" :
				break;
		}
		return tempVal;
	}
}
